package com.lmx.repoDomain.repository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lmx.persistence.service.AssessmentService;
import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.tmodel.Assessment;
import com.lmx.repoDomain.tmodel.AssessmentIndicatorResult;

/**
 * 考核结果详细
 *
 * @author ytche
 * @date 2017年8月16日
 *
 */
@Service
@Scope(value = "singleton")
public class AssessmentIndicatorResultServiceImpl extends
		BaseCrudServiceImpl<AssessmentIndicatorResult> implements
		AssessmentIndicatorResultService {
	@Autowired
	private AssessmentService assessmentService;

	@Override
	@Transactional
	public AssessmentIndicatorResult save(AssessmentIndicatorResult entity) {
		Assessment assessment = entity.getAssessment();
		Integer changeScore = entity.getId() == null ? entity.getScore()
				: entity.getScore() - super.findOne(entity.getId()).getScore();
		assessment.setPoint(assessment.getPoint() == null ? changeScore
				: assessment.getPoint() + changeScore);
		assessmentService.save(assessment);
		return super.save(entity);
	}
}
